package com.jiyi.exception;


import android.app.Dialog;
import android.content.Context;
import android.support.v4.widget.SwipeRefreshLayout;

import com.swift.maintenance.utils.ToastUtil;
import com.swift.utils.DialogTool;

import io.reactivex.disposables.Disposable;

/**
 * Created by 12262 on 2016/6/5.
 */
public abstract class SampleRefreshObserver<T> extends MyObserver<T>{
    private Dialog dialog;
    private SwipeRefreshLayout srl;
    private Context context;

    public SampleRefreshObserver(Context context,SwipeRefreshLayout srl) {
        dialog = DialogTool.creatDialog(dialog,context);
        this.context = context;
        this.srl = srl;
    }

    @Override
    public void onSubscribe(Disposable d) {
        dialog.show();
    }

    @Override
    protected void onError(ApiException ex) {
        srl.setRefreshing(false);
        dialog.dismiss();
        ToastUtil.getInstances().showMsg(ex.getDisplayMessage());
    }


    @Override
    public void onNext(T t) {

    }

    @Override
    public void onComplete() {
        srl.setRefreshing(false);
        dialog.dismiss();
    }
}
